package com.ld.collegetask.beans;

import android.app.Activity;
import android.content.Intent;
import android.databinding.BaseObservable;
import android.databinding.BindingAdapter;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import com.ld.collegetask.OrderMemberInfoActivity;
import com.ld.collegetask.R;
import com.ld.collegetask.login.LoginActivity;
import com.ld.collegetask.utils.AppApplication;
import com.ld.collegetask.utils.CurrencyUtils;
import com.ld.collegetask.utils.SharePreference;
import com.squareup.picasso.Picasso;

import static android.graphics.Color.parseColor;

/**
 * Created by 樊海波 on 2017/9/20.
 */

//soloman
public class OrderBean extends BaseObservable {


    /**
     * userUserId : 46
     * orderendaddress : 湖北省武汉市江岸区
     * orderOstatus : 1
     * ordercomplaints : 0
     * orderOremark : 234******
     * orderOlife:"2018-02-12 11:57:00.0",
     * orderStatusonetime : 2018-02-05 08:55:20.0
     * genderlimit : 2
     * userRealname : lx123
     * orderOcommission : 0
     * receiveUserId :
     * orderOcost : 1
     * orderNumber : 20180205085520659
     * orderOdis : 1
     * orderOrealname : 2141
     * orderId : 50
     * orderOphone : 2341
     */

    private int userUserId;
    private int userId;
    private String userImg;
    private String orderendaddress;
    private int orderOstatus;
    private int ordercomplaints;
    private String orderOremark;
    private String orderOlife;
    private String orderStatusonetime;
    private int genderlimit;
    private String userRealname;
    private String orderOcommission;
    private String receiveUserId;
    private String orderOcost;
    private String orderNumber;
    private String orderOdis;
    private String orderOrealname;
    private int orderId;
    private String orderOphone;
    private String userUserSchoolName;

    public String getUserImg() {
        return userImg;
    }

    public void setUserImg(String userImg) {
        this.userImg = userImg;
    }

    //soloman
    public void click(View view) {
        Activity mActivity = (Activity) view.getContext();
        SharePreference sp = new SharePreference(mActivity);
        if (sp.getLoginState()) {
            Intent it = new Intent(mActivity, OrderMemberInfoActivity.class);
            it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            it.putExtra("orderId", orderId);
            mActivity.startActivityForResult(it, 1);
        }else {
            Intent it = new Intent(mActivity, LoginActivity.class);
            mActivity.startActivity(it);
        }
    }

    public String getUserUserSchoolName() {
        return userUserSchoolName;
    }

    public void setUserUserSchoolName(String userUserSchoolName) {
        this.userUserSchoolName = userUserSchoolName;
    }

    public String getOrderOlife() {
        return orderOlife.split("\\.")[0];
    }

    public String getOrderOlife_1() {
        return orderOlife.split("\\.")[0].replaceAll("\\d{4}\\-","");
    }

    public void setOrderOlife(String orderOlife) {
        this.orderOlife = orderOlife;
    }

    //    public Integer getSchoolName() {
//        return userUserSchoolName;
//    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getOrderOstatus_Color() {
        int i = 0;
        if (genderlimit == -2)
            i = parseColor("#EAEE76");
        if (genderlimit == -1)
            i = parseColor("#EAEE76");
        if (genderlimit == 0)
            i = parseColor("#EAEE76");
        if (genderlimit == 1)
            i = parseColor("#EAEE76");
        if (genderlimit == 2)
            i = parseColor("#EAEE76");
        if (genderlimit == 3)
            i = parseColor("#EAEE76");
        if (genderlimit == 4)
            i = parseColor("#EAEE76");
        return i;
    }

    @BindingAdapter({"bind:OrderBeanImg"})
    public static void OrderBeanImage(ImageView view, int imageUrl) {
        if (imageUrl == 1) {
            imageUrl = R.drawable.status_1;
        } else if (imageUrl == 2) {
            imageUrl = R.drawable.status_2;
        } else if (imageUrl == 3) {
            imageUrl = R.drawable.status_3;
        } else if (imageUrl == 4){
            imageUrl = R.drawable.status_4;
        }else {
            imageUrl = R.drawable.status_4;
        }
        Picasso.with(view.getContext())
                .load(imageUrl)
//                .placeholder(R.drawable.placeholder)
                .into(view);
    }

    @BindingAdapter({"bind:OrderUserUserImg"})
    public static void OrderUserUserImg(ImageView view, String imageUrl) {
        Picasso.with(view.getContext())
                .load(AppApplication.server+imageUrl)
                .placeholder(R.drawable.user_img)
                .fit()
                .into(view);
    }

    public boolean getEnabled() {
        boolean bool = false;
        if (userId == userUserId) {                         //如果自己的用户id == 发任务的用户id，任务主
            if (orderOstatus == -2)
                bool = false;
            if (orderOstatus == -1)
                bool = false;
            if (orderOstatus == 0)
                bool = false;
            if (orderOstatus == 1)
                bool = false;
            if (orderOstatus == 2)
                bool = false;
            if (orderOstatus == 3)
                bool = true;
            if (orderOstatus == 4)
                bool = false;
        } else if ((userId + "").equals(receiveUserId)) {     //如果自己的用户id == 接单任务的用户id，接单主
            if (orderOstatus == -2)
                bool = false;
            if (orderOstatus == -1)
                bool = false;
            if (orderOstatus == 0)
                bool = false;
            if (orderOstatus == 1)
                bool = true;
            if (orderOstatus == 2)
                bool = true;
            if (orderOstatus == 3)
                bool = false;
            if (orderOstatus == 4)
                bool = false;
        } else {                                            //游客
            if (orderOstatus == -2)
                bool = false;
            if (orderOstatus == -1)
                bool = false;
            if (orderOstatus == 0)
                bool = false;
            if (orderOstatus == 1)
                bool = true;
            if (orderOstatus == 2)
                bool = false;
            if (orderOstatus == 3)
                bool = false;
            if (orderOstatus == 4)
                bool = false;
        }
        return bool;
    }

    public int getOrderOstatus_text_Color() {
        int i = 0;
        if (orderOstatus == -2)
            i = parseColor("#C67600");
        if (orderOstatus == -1)
            i = parseColor("#C67600");
        if (orderOstatus == 0)
            i = parseColor("#C67600");
        if (orderOstatus == 1)
            i = parseColor("#C67600");
        if (orderOstatus == 2)
            i = parseColor("#C67600");
        if (orderOstatus == 3)
            i = parseColor("#C67600");
        if (orderOstatus == 4)
            i = parseColor("#C67600");
        return i;
    }

    public String getMoney_2() {
        return "¥ " + CurrencyUtils.add(orderOcost, orderOcommission) + " 元";
    }

    public String getMoney_1() {
        return CurrencyUtils.add(orderOcost, orderOcommission) + " 元";
    }

    public String getMoney() {
        return CurrencyUtils.add(orderOcost, orderOcommission);
    }

    public int getOrderOstatus_visibility() {
        int i = 0;
        if (orderOstatus == -2)
            i = View.INVISIBLE;
        if (orderOstatus == -1)
            i = View.INVISIBLE;
        if (orderOstatus == 0)
            i = View.VISIBLE;
        if (orderOstatus == 1)
            i = View.VISIBLE;
        if (orderOstatus == 2)
            i = View.VISIBLE;
        if (orderOstatus == 3)
            i = View.VISIBLE;
        if (orderOstatus == 4)
            i = View.VISIBLE;
        return i;
    }


    public String getOrderOstatus_1() {
        String str = "";
        if (orderOstatus == -1)
            str = "已取消";
        if (orderOstatus == -2)
            str = "已禁用";
        if (orderOstatus == 0)
            str = "已过期";
        if (orderOstatus == 1)
            str = "已发布";
        if (orderOstatus == 2)
            str = "已抢单";
        if (orderOstatus == 3)
            str = "已送达";
        if (orderOstatus == 4)
            str = "已结单";
        return str;
    }

    public int getGenderlimit_text_Color() {
        int i = 0;
        if (genderlimit == 0)
            i = parseColor("#FF93C3");
        if (genderlimit == 1)
            i = parseColor("#1FAEC8");
        if (genderlimit == 2)
            i = parseColor("#FF93C3");
        return i;
    }

    public int getGenderlimit_Color() {
        int i = 0;
        if (genderlimit == 0)
            i = parseColor("#FFC0FF");
        if (genderlimit == 1)
            i = parseColor("#A8E5EF");
        if (genderlimit == 2)
            i = parseColor("#FF93C3");
        return i;
    }


    public String getGenderlimit_1() {
        String str = "";
        if (genderlimit == 0)
            str = "限女生";
        if (genderlimit == 1)
            str = "限男生";
        if (genderlimit == 2)
            str = "";
        return str;
    }

    public int getGenderlimit_visibility() {
        int i = 0;
        if (genderlimit == 0)
            i = View.VISIBLE;
        if (genderlimit == 1)
            i = View.VISIBLE;
        if (genderlimit == 2)
            i = View.GONE;
        return i;
    }

    public String getOrderOcommission_1() {
        return orderOcommission + " 元";
    }

    public String getOrderOcommission_2() {
        return "¥ " + orderOcommission + " 元";
    }

    public String getOrderOcost_1() {
        return orderOcost + " 元";
    }

    public String getOrderOcost_2() {
        return "¥ " + orderOcost + " 元";
    }

    public int getButtonBackground() {
        int color = 0;
        if (userId == userUserId) {                      //如果自己的用户id == 发任务的用户id，任务主
            if (orderOstatus == -2)
                color = Color.parseColor("#AAAAAA");
            if (orderOstatus == -1)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 0)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 1)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 2)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 3)
                color = parseColor("#40D15C");
            if (orderOstatus == 4)
                color = parseColor("#AAAAAA");
        } else if ((userId + "").equals(receiveUserId)) {     //如果自己的用户id == 接单任务的用户id，接单主
            if (orderOstatus == -2)
                color = Color.parseColor("#AAAAAA");
            if (orderOstatus == -1)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 0)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 1)
                color = parseColor("#40D15C");
            if (orderOstatus == 2)
                color = parseColor("#40D15C");
            if (orderOstatus == 3)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 4)
                color = parseColor("#AAAAAA");
        } else {                                            //游客
            if (orderOstatus == -2)
                color = Color.parseColor("#AAAAAA");
            if (orderOstatus == -1)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 0)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 1)
                color = parseColor("#40D15C");
            if (orderOstatus == 2)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 3)
                color = parseColor("#AAAAAA");
            if (orderOstatus == 4)
                color = parseColor("#AAAAAA");
        }
        return color;
    }

    public String getButtonText() {
        String str = "";
        if (userId == userUserId) {                         //如果自己的用户id == 发任务的用户id，任务主
            if (orderOstatus == -2)
                str = "已取消";
            if (orderOstatus == -1)
                str = "已禁止";
            if (orderOstatus == 0)
                str = "已过期";
            if (orderOstatus == 1)
                str = "已发单";
            if (orderOstatus == 2)
                str = "已接单";
            if (orderOstatus == 3)
                str = "已完成";
            if (orderOstatus == 4)
                str = "交易完成";
        } else if ((userId + "").equals(receiveUserId)) {     //如果自己的用户id == 接单任务的用户id，接单主
            if (orderOstatus == -2)
                str = "已取消";
            if (orderOstatus == -1)
                str = "已禁止";
            if (orderOstatus == 0)
                str = "已过期";
            if (orderOstatus == 1)
                str = "我要抢单";
            if (orderOstatus == 2)
                str = "确认";
            if (orderOstatus == 3)
                str = "等待确认";
            if (orderOstatus == 4)
                str = "交易完成";
        } else {                                            //游客
            if (orderOstatus == -2)
                str = "已取消";
            if (orderOstatus == -1)
                str = "已禁止";
            if (orderOstatus == 0)
                str = "已过期";
            if (orderOstatus == 1)
                str = "我要抢单";
            if (orderOstatus == 2)
                str = "来晚了";
            if (orderOstatus == 3)
                str = "来晚了";
            if (orderOstatus == 4)
                str = "来晚了";
        }
        return str;
    }

    public int getUserUserId() {
        return userUserId;
    }

    public void setUserUserId(int userUserId) {
        this.userUserId = userUserId;
    }

    public String getOrderendaddress() {
        return orderendaddress;
    }

    public void setOrderendaddress(String orderendaddress) {
        this.orderendaddress = orderendaddress;
    }

    public int getOrderOstatus() {
        return orderOstatus;
    }

    public void setOrderOstatus(int orderOstatus) {
        this.orderOstatus = orderOstatus;
    }

    public int getOrdercomplaints() {
        return ordercomplaints;
    }

    public void setOrdercomplaints(int ordercomplaints) {
        this.ordercomplaints = ordercomplaints;
    }

    public String getOrderOremark() {
        return orderOremark;
    }

    public void setOrderOremark(String orderOremark) {
        this.orderOremark = orderOremark;
    }

    public String getOrderStatusonetime() {
        return orderStatusonetime.split("\\.")[0];
    }

    public String getOrderStatusonetime_1() {
        return orderStatusonetime.split("\\.")[0].replaceAll("\\d{4}\\-","");
    }

    public void setOrderStatusonetime(String orderStatusonetime) {
        this.orderStatusonetime = orderStatusonetime;
    }

    public int getGenderlimit() {
        return genderlimit;
    }

    public void setGenderlimit(int genderlimit) {
        this.genderlimit = genderlimit;
    }

    public String getUserRealname() {
        return userRealname;
    }

    public void setUserRealname(String userRealname) {
        this.userRealname = userRealname;
    }

    public String getOrderOcommission() {
        return orderOcommission;
    }

    public void setOrderOcommission(String orderOcommission) {
        this.orderOcommission = orderOcommission;
    }

    public String getReceiveUserId() {
        return receiveUserId;
    }

    public void setReceiveUserId(String receiveUserId) {
        this.receiveUserId = receiveUserId;
    }

    public String getOrderOcost() {
        return orderOcost;
    }

    public void setOrderOcost(String orderOcost) {
        this.orderOcost = orderOcost;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getOrderOdis() {
        return orderOdis;
    }

    public void setOrderOdis(String orderOdis) {
        this.orderOdis = orderOdis;
    }

    public String getOrderOrealname() {
        return orderOrealname;
    }

    public void setOrderOrealname(String orderOrealname) {
        this.orderOrealname = orderOrealname;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getOrderOphone() {
        return orderOphone;
    }

    public void setOrderOphone(String orderOphone) {
        this.orderOphone = orderOphone;
    }
}
